package org.scmpatrol.core.scm.init;

import javax.ejb.EJB;

import org.apache.log4j.Logger;
import org.jboss.annotation.ejb.Depends;
import org.jboss.annotation.ejb.Management;
import org.jboss.annotation.ejb.Service;
import org.scmpatrol.core.SCMPatrolManagerLocal;

/**
 * This class is the main class used to start the components where the ear is
 * deployed.
 * 
 */
@Service
@Management(SCMPatrolServiceManagement.class)
@Depends(value="jboss.j2ee:ear=ear-0.1-SNAPSHOT.ear,jar=core-0.1-SNAPSHOT.jar,name=SCMPatrolManagerBean,service=EJB3")
public class SCMPatrolService implements SCMPatrolServiceManagement {
	private final static Logger LOGGER = Logger
			.getLogger(SCMPatrolService.class);

	Integer status;
	
	@EJB(beanName="SCMPatrolManagerBean")
	private SCMPatrolManagerLocal scmPatrolManager;
	
	// Lifecycle methods
	public void create() throws Exception {
		status = 0;
	}

	public void start() throws Exception {
		status = 1;
		LOGGER.info("Starting SCMPatrol....");
		
		scmPatrolManager.startSCMPatrol();		
		
		LOGGER.info("Started SCMPatrol");
		status = 2;
	}

	public void stop() {
		status = 0;
	}

	public void destroy() {
		
	}

	public String getStatus() {
		return String.valueOf(status);
	} 
}
